package com.hubei.car.controller;

import com.hubei.car.annotation.GetApi;
import com.hubei.car.annotation.PostApi;
import com.hubei.car.dto.req.PageCondition;
import com.hubei.car.entity.MsMemberCoupon;
import com.hubei.car.entity.Result;
import com.hubei.car.service.MsCouponService;
import com.hubei.car.swaggerParam.MsCouponQueryParam;
import com.hubei.car.swaggerParam.MsMemberCouponQueryParam;
import com.hubei.car.utils.UserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 礼券接口
 * @author huanghaiasheng
 * @create 2019-11-18
 */
@RestController
@Api(value = "礼券接口",tags = "礼券接口")
@RequestMapping("/coupon")
public class MsCouponController {

    @Autowired
    private MsCouponService msCouponService;
    @Autowired
    UserUtil userUtil;

    @PostApi(value = "/queryMsCouponPage",auth = false)
    @ApiOperation("礼券查询")
    public Result queryMsCouponPage(@RequestBody @Valid MsCouponQueryParam msCouponQueryParam){
        return msCouponService.queryMsCouponPage(msCouponQueryParam);
    }

    @PostApi(value = "/addMsMemberCoupon/{couponid}")
    @ApiOperation("领取礼券")
    public Result addMsMemberCoupon(@PathVariable("couponid") Long couponid){
        return msCouponService.addMsMemberCoupon(couponid, userUtil.getCurrentUser());
    }

    @PostApi(value = "/queryMy")
    @ApiOperation("查询翻页我的优惠券")
    public Result queryMy(@RequestBody @Valid MsMemberCouponQueryParam msMemberCouponQueryParam){
        return msCouponService.queryMy(msMemberCouponQueryParam, userUtil.getCurrentUser());
    }
}
